package fun.zhufn.oldcomm.view;

import fun.zhufn.oldcomm.OldManagerController;
import fun.zhufn.oldcomm.PathManagerController;
import fun.zhufn.oldcomm.UserManagerController;
import fun.zhufn.oldcomm.model.bo.Path;
import fun.zhufn.oldcomm.model.bo.User;
import fun.zhufn.oldcomm.model.bo.customlist.UserList;
import fun.zhufn.oldcomm.model.bo.json.JsonMap;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.awt.event.*;
import java.util.Locale;
import java.util.Objects;
import java.util.logging.Logger;

public class RootDesk {
    private static final UserManagerController userContro = UserManagerController.getInstance();
    private static final OldManagerController oldContro = OldManagerController.getInstance();
    private static final PathManagerController pathContro = PathManagerController.getInstance();
    private static JFrame frame;
    private static final Logger log = Logger.getLogger(RootDesk.class.toString());

    private boolean needLogOut = false;

    public RootDesk() {
        frame = new JFrame("RootDesk");
        //FlatLightLaf.setup();
        $$$setupUI$$$();
        new_jb.addActionListener(e -> {
            frame.setVisible(false);
            new ModifyUser().start(null, frame, userContro.getUser().permission == 3);
        });
        delete_jb.addActionListener(e -> {
            String acc;
            try {
                acc = (String) tablenr[table1.getSelectedRow()][0];
            } catch (Exception err) {
                JOptionPane.showMessageDialog(null, "请选择要删除的用户");
                return;
            }
            log.info("删除：" + acc);
            if (acc.equals(userContro.getUser().getAccount())) {
                needLogOut = true;
            }
            if (userContro.removeUser(acc)) {
                JOptionPane.showMessageDialog(null, "删除成功！");
            } else {
                JOptionPane.showMessageDialog(null, "删除失败");
            }
            updateInfo();
            //JOptionPane.showMessageDialog(null, "不会！");
        });
        edit_jb.addActionListener(e -> {
            String acc;
            try {
                log.info("" + tablenr[table1.getSelectedRow()][0]);
                acc = (String) tablenr[table1.getSelectedRow()][0];
                frame.setVisible(false);
            } catch (Exception err) {
                JOptionPane.showMessageDialog(null, "请选择要修改的用户");
                return;
            }
            User mou = userContro.getUserByAccount(acc);
            frame.setVisible(false);
            new ModifyUser().start(mou, frame, userContro.getUser().permission == 3);
            //updateUserTable();
        });
        exit_jb.addActionListener(e -> {
            frame.dispose();
            new Login().start();
        });
        addold_jb.addActionListener(actionEvent -> {
            new ModifyOld().start(null, frame);
            //窗口可见性变化，不用手动更新列表
        });
        removeold_jb.addActionListener(actionEvent -> {
            if (list1.getSelectedIndex() == -1) return;
            oldContro.removeOld(oldContro.getOldList().get(list1.getSelectedIndex()).getId());
            updateInfo();
        });
        list1.addListSelectionListener(e -> {
            if (list1.getSelectedIndex() != -1) {
                var svr = oldContro.getOldList().get(list1.getSelectedIndex()).getServer();
                editserver_jb.setEnabled(true);
                if (svr == null) {
                    svr_jta.setText("未选择服务人员");
                } else {
                    svr_jta.setText(userContro.getUserByAccount(svr).toString());
                }
            } else {

                editserver_jb.setEnabled(false);
                svr_jta.setText("选择老人以查看服务人员");
            }
        });
        editserver_jb.addActionListener(actionEvent -> {
            if (list1.getSelectedIndex() == -1) return;
            var t = oldContro.getOldList().get(list1.getSelectedIndex());
            var acc = JOptionPane.showInputDialog("请输入要添加的服务人员账号！");
            var u = userContro.getUserByAccount(acc);
            if (u != null && u.permission == 2) {
                oldContro.setOldSrv(t.getId(), acc);
                //窗口可见性变化，不用手动更新列表
            } else {
                JOptionPane.showMessageDialog(null, "请输入正确的服务人员账号！");
            }
        });
        serverq_jb.addActionListener(actionEvent -> {
            var gj = JOptionPane.showInputDialog("请输入您要查询的生活管家账号！");
            StringBuilder r = new StringBuilder();
            r.append("这位生活管家服务的老人有：\n");
            for (var v : oldContro.getOldList()) {
                if (Objects.equals(v.getServer(), gj)) {
                    r.append("\t").append(v.getId()).append(": ").append(v.getName()).append("\n");
                }
            }
            JOptionPane.showMessageDialog(null, r.toString());
        });
        edit_old_jb.addActionListener(actionEvent -> new ModifyOld().start(oldContro.getOldList().get(list1.getSelectedIndex()), frame));
        addbus_jb.addActionListener(actionEvent -> new ModifyPath().start(null, frame));
        editbus_jb.addActionListener(actionEvent -> {
            if (path_jtb.getSelectedRow() == -1) return;
            int i = path_jtb.getSelectedRow();
            new ModifyPath().start(pathContro.getPathList().get(i), frame);
        });
        removebus_jb.addActionListener(actionEvent -> {
            if (path_jtb.getSelectedRow() == -1) return;
            int i = path_jtb.getSelectedRow();
            pathContro.removePath(pathContro.getPathList().get(i).getCode());
            updateInfo();
        });
        setend_jb.addActionListener(actionEvent -> {
            if (path_jtb.getSelectedRow() == -1) return;
            int i = path_jtb.getSelectedRow();
            try {
                var ori = pathContro.getPathList().get(i);
                var edt = Integer.parseInt(JOptionPane.showInputDialog("截止为发车前几小时？（请输入正整数）"));
                var gt = ori.getTime().split(":");
                var nh = Integer.parseInt(gt[0]) - edt;
                if (edt < 0 || nh < 0) {
                    JOptionPane.showMessageDialog(null, "不能为负数且只能在当天截止！");
                    return;
                }
                ori.setEndTime(edt);
                pathContro.editPath(ori);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "请检查您的输入");
                e.printStackTrace();
            }
            updateInfo();
        });
        newcustomer_jb.addActionListener(actionEvent -> {
            if (path_jtb.getSelectedRow() == -1) return;
            int i = path_jtb.getSelectedRow();
            try {
                var ori = pathContro.getPathList().get(i);
                if (ori.getEndTime() == null) {
                    JOptionPane.showMessageDialog(null, "未设置截止时间！");
                    return;
                }
                var id = Integer.parseInt(JOptionPane.showInputDialog("请输入老人的ID？"));
                for (var v : ori.getOrders()) {
                    if (((Integer) (((JsonMap) v).get("oldId"))) == id) {
                        JOptionPane.showMessageDialog(null, "约过了");
                        return;
                    }
                }
                boolean flag = false;
                for (var v : oldContro.getOldList()) {
                    if (v.getId() == id) {
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    JOptionPane.showMessageDialog(null, "老人不存在");
                    return;
                }
                var day = Integer.parseInt(JOptionPane.showInputDialog("是在本周几预约的？（请输入1-7，只能是发车日）"));
                if (day == 7) day = 0;
                if (!(day == ori.getDay())) throw new Exception();
                var time = JOptionPane.showInputDialog("请输入具体时间（格式：13:30）");
                var t = time.split(":");
                if (t.length == 2) {
                    try {
                        var h = Integer.parseInt(t[0]);
                        var m = Integer.parseInt(t[1]);
                        if (!(h >= 0 && h < 24 && m >= 0 && m < 60)) {
                            JOptionPane.showMessageDialog(null, "时间格式为24小时制的时:分");
                            return;
                        } else {
                            if (day == ori.getDay()) {
                                var t2 = ori.getTime().split(":");
                                var h2 = Integer.parseInt(t2[0]);
                                h2 -= ori.getEndTime();
                                var m2 = Integer.parseInt(t2[1]);
                                if (!(h < h2 || h == h2 && m <= m2)) {
                                    JOptionPane.showMessageDialog(null, "不得超过截止时间！");
                                    return;
                                }
                            }
                        }
                    } catch (Exception err) {
                        JOptionPane.showMessageDialog(null, "时间格式为24小时制的时:分");
                        return;
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "时间格式为24小时制的时:分");
                    return;
                }
                var mp = new JsonMap();
                mp.put("oldId", id);
                mp.put("inf", Path.week[day] + " " + time);
                var ol = ori.getOrders();
                ol.add(mp);
                ori.setOrders(ol);
                pathContro.editPath(ori);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "请检查您的输入");
                e.printStackTrace();
            }
            updateInfo();
        });
        showcustomer_jb.addActionListener(actionEvent -> {
            if (path_jtb.getSelectedRow() == -1) return;
            int i = path_jtb.getSelectedRow();
            StringBuilder s = new StringBuilder("乘客如下：\n");
            for (var v : pathContro.getPathList().get(i).getOrders()) {
                s.append(((JsonMap) v).get("oldId"));
                s.append(" ");
                var l = oldContro.getOldList();
                boolean flag = false;
                for (var o : l) {
                    if (o.getId() == (Integer) ((JsonMap) v).get("oldId")) {
                        s.append(o.getName());
                        s.append(" ");
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    s.append("用户已注销 ");
                }
                s.append("预约时间：");
                s.append(((JsonMap) v).get("inf"));
                s.append("\n");
            }
            JOptionPane.showMessageDialog(null, s.toString());
        });
    }

    /**
     * 启动界面
     */
    public void start() {
        log.info("进入管理员界面");
        frame.setContentPane(this.root_desk_jp);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        //frame.setResizable(false);
        //frame.setSize(500, 600);
        //frame.setMinimumSize(new Dimension(500, 600));
        frame.pack();
        frame.setMinimumSize(frame.getSize());
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        int x = (int) (toolkit.getScreenSize().getWidth() - frame.getWidth()) / 2;
        int y = (int) (toolkit.getScreenSize().getHeight() - frame.getHeight()) / 2;
        frame.setLocation(x, y);
        //frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        if (userContro.getUser().permission != 3) {
            addold_jb.setEnabled(false);
            removeold_jb.setEnabled(false);
            if (userContro.getUser().permission == 2) {
                svrmsg_jlb.setText("生活管家您好，您可以查看您服务的老人但不能查询其他生活管家的信息");
                busmsg_jlb.setText("生活管家您好，您来错地方了");
                addbus_jb.setEnabled(false);
            } else {
                edit_old_jb.setEnabled(false);
                svrmsg_jlb.setText("后勤管理您好，您来错地方了");
                busmsg_jlb.setText("后勤管理您好，您可以编辑线路信息");
            }
            msg1.setText("您不是管理员，只能查看自己的信息");
            new_jb.setEnabled(false);
            delete_jb.setEnabled(false);
        } else {
            msg1.setText("欢迎您，尊贵的管理员");
            svrmsg_jlb.setText("管理员您好，您可以管理所有的老人并查询所有生活管家的信息");
            busmsg_jlb.setText("管理员您好，您可以编辑线路信息");
            serverq_jb.setEnabled(true);
        }

    }

    private JPanel root_desk_jp;
    private JTable table1;
    private JButton edit_jb;
    private JButton new_jb;
    private JButton delete_jb;
    private JTabbedPane tabbedPane1;
    private JPanel jp1;
    private JPanel jp2;
    private JLabel msg1;
    private JButton exit_jb;
    private JList<Object> list1;
    private JButton addold_jb;
    private JButton removeold_jb;
    private JButton editserver_jb;
    private JTextArea svr_jta;
    private JLabel svrmsg_jlb;
    private JButton serverq_jb;
    private JButton edit_old_jb;
    private JPanel bus_jp;
    private JButton addbus_jb;
    private JTable path_jtb;
    private JButton editbus_jb;
    private JButton removebus_jb;
    private JButton newcustomer_jb;
    private JButton showcustomer_jb;
    private JButton setend_jb;
    private JLabel busmsg_jlb;

    private Object[][] tablenr;

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        createUIComponents();
        root_desk_jp = new JPanel();
        root_desk_jp.setLayout(new GridBagLayout());
        tabbedPane1 = new JTabbedPane();
        tabbedPane1.setName("用户");
        GridBagConstraints gbc;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        root_desk_jp.add(tabbedPane1, gbc);
        jp1 = new JPanel();
        jp1.setLayout(new GridBagLayout());
        jp1.setName("");
        tabbedPane1.addTab("用户", jp1);
        edit_jb = new JButton();
        edit_jb.setText("编辑选中");
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        jp1.add(edit_jb, gbc);
        delete_jb = new JButton();
        delete_jb.setText("删除选中");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        jp1.add(delete_jb, gbc);
        final JScrollPane scrollPane1 = new JScrollPane();
        scrollPane1.setHorizontalScrollBarPolicy(32);
        scrollPane1.setVerticalScrollBarPolicy(22);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 3;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        jp1.add(scrollPane1, gbc);
        table1.setFillsViewportHeight(true);
        scrollPane1.setViewportView(table1);
        new_jb = new JButton();
        new_jb.setText("新建用户");
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        jp1.add(new_jb, gbc);
        msg1 = new JLabel();
        msg1.setText("Label");
        msg1.setVisible(true);
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 3;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.insets = new Insets(5, 5, 5, 5);
        jp1.add(msg1, gbc);
        jp2 = new JPanel();
        jp2.setLayout(new GridBagLayout());
        jp2.setAutoscrolls(false);
        jp2.setName("生活管家");
        tabbedPane1.addTab("生活管家", jp2);
        removeold_jb = new JButton();
        Font removeold_jbFont = this.$$$getFont$$$(null, -1, 18, removeold_jb.getFont());
        if (removeold_jbFont != null) removeold_jb.setFont(removeold_jbFont);
        removeold_jb.setText("-");
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        jp2.add(removeold_jb, gbc);
        final JScrollPane scrollPane2 = new JScrollPane();
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 3;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        jp2.add(scrollPane2, gbc);
        list1 = new JList<>();
        scrollPane2.setViewportView(list1);
        addold_jb = new JButton();
        Font addold_jbFont = this.$$$getFont$$$(null, -1, 18, addold_jb.getFont());
        if (addold_jbFont != null) addold_jb.setFont(addold_jbFont);
        addold_jb.setText("+");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        jp2.add(addold_jb, gbc);
        editserver_jb = new JButton();
        editserver_jb.setEnabled(false);
        Font editserver_jbFont = this.$$$getFont$$$(null, -1, 18, editserver_jb.getFont());
        if (editserver_jbFont != null) editserver_jb.setFont(editserver_jbFont);
        editserver_jb.setText("修改选中的服务人员");
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        jp2.add(editserver_jb, gbc);
        svr_jta = new JTextArea();
        svr_jta.setEditable(false);
        svr_jta.setEnabled(true);
        svr_jta.setText("选择老人以查看服务人员");
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = 3;
        jp2.add(svr_jta, gbc);
        svrmsg_jlb = new JLabel();
        svrmsg_jlb.setText("");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 5;
        jp2.add(svrmsg_jlb, gbc);
        serverq_jb = new JButton();
        serverq_jb.setEnabled(false);
        Font serverq_jbFont = this.$$$getFont$$$(null, -1, 18, serverq_jb.getFont());
        if (serverq_jbFont != null) serverq_jb.setFont(serverq_jbFont);
        serverq_jb.setText("按管家查询");
        gbc = new GridBagConstraints();
        gbc.gridx = 3;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        jp2.add(serverq_jb, gbc);
        edit_old_jb = new JButton();
        Font edit_old_jbFont = this.$$$getFont$$$(null, -1, 18, edit_old_jb.getFont());
        if (edit_old_jbFont != null) edit_old_jb.setFont(edit_old_jbFont);
        edit_old_jb.setText("编辑");
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        jp2.add(edit_old_jb, gbc);
        bus_jp = new JPanel();
        bus_jp.setLayout(new GridBagLayout());
        tabbedPane1.addTab("后勤管理", bus_jp);
        final JScrollPane scrollPane3 = new JScrollPane();
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 7;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        bus_jp.add(scrollPane3, gbc);
        path_jtb.setFillsViewportHeight(true);
        scrollPane3.setViewportView(path_jtb);
        editbus_jb = new JButton();
        editbus_jb.setText("编辑选中");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        bus_jp.add(editbus_jb, gbc);
        removebus_jb = new JButton();
        removebus_jb.setText("删除选中");
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        bus_jp.add(removebus_jb, gbc);
        newcustomer_jb = new JButton();
        newcustomer_jb.setText("预约选中");
        gbc = new GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        bus_jp.add(newcustomer_jb, gbc);
        showcustomer_jb = new JButton();
        showcustomer_jb.setText("查看选中路线乘客");
        gbc = new GridBagConstraints();
        gbc.gridx = 5;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        bus_jp.add(showcustomer_jb, gbc);
        addbus_jb = new JButton();
        addbus_jb.setText("添加线路");
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        bus_jp.add(addbus_jb, gbc);
        setend_jb = new JButton();
        setend_jb.setText("设置选中截止");
        gbc = new GridBagConstraints();
        gbc.gridx = 3;
        gbc.gridy = 1;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        bus_jp.add(setend_jb, gbc);
        busmsg_jlb = new JLabel();
        busmsg_jlb.setText("");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 6;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.WEST;
        bus_jp.add(busmsg_jlb, gbc);
        exit_jb = new JButton();
        exit_jb.setText("退出登录");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        root_desk_jp.add(exit_jb, gbc);
    }

    /**
     * @noinspection ALL
     */
    private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
        if (currentFont == null) return null;
        String resultName;
        if (fontName == null) {
            resultName = currentFont.getName();
        } else {
            Font testFont = new Font(fontName, Font.PLAIN, 10);
            if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
                resultName = fontName;
            } else {
                resultName = currentFont.getName();
            }
        }
        Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
        boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac");
        Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());
        return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return root_desk_jp;
    }

    private void createUIComponents() {
        table1 = new JTable(new Object[0][0], new String[]{"用户名", "姓名", "权限等级", "生日", "电话", "性别"}) {
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        table1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        path_jtb = new JTable(new Object[0][0], new String[]{"线路代码", "线路名称", "方向", "日期", "时段", "类别", "发车时间", "截止时间", "预约人数"}) {
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        path_jtb.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowActivated(WindowEvent e) {
                super.windowActivated(e);
                updateInfo();
            }
        });
    }

    /**
     * 更新信息
     */
    private void updateInfo() {

        list1.setListData(oldContro.getOldList().stream().filter((a) -> {
            var u = userContro.getUser();
            var p = u.permission;
            return p == 3 || (p == 2 && (Objects.equals(u.getAccount(), a.getServer())));
        }).map((a) -> a.getId() + ": " + a.getName() + " " + (a.isMale() ? "男 " : "女 ") + a.getBirthday() + " " + a.getPhone()).toArray());

        if (list1.getSelectedIndex() != -1) {
            var svr = oldContro.getOldList().get(list1.getSelectedIndex()).getServer();
            editserver_jb.setEnabled(true);
            if (svr == null) {
                svr_jta.setText("未选择服务人员");
            } else {
                svr_jta.setText(userContro.getUserByAccount(svr).toString());
            }
        } else {

            editserver_jb.setEnabled(false);
            svr_jta.setText("选择老人以查看服务人员");
        }
        try {
            var tl = pathContro.getPathList();
            tablenr = new Object[tl.size()][10];
            DefaultTableModel tbmd = new DefaultTableModel(new String[]{"线路代码", "线路名称", "方向", "日期", "类别", "时段", "发车时间", "截止时间", "预约人数", "备注"}, 0);
            tbmd.setRowCount(0);
            int j = 0;
            for (Path path : tl) {
                if (userContro.getUser().permission == 2)
                    continue;
                tablenr[j][0] = path.getCode();
                tablenr[j][1] = path.getName();
                tablenr[j][2] = path.isUp() ? "上行" : "下行";
                tablenr[j][3] = path.sayDay();
                tablenr[j][4] = path.isInland() ? "岛内" : "岛外";
                tablenr[j][5] = path.getAmPm();
                tablenr[j][6] = path.getTime().replace(":", "点") + "分";
                tablenr[j][7] = path.sayEndTime();
                tablenr[j][8] = path.getOrders().size();
                tablenr[j][9] = path.getNote();

                tbmd.addRow(tablenr[j]);
                ++j;
            }
            path_jtb.setModel(tbmd);
        } catch (Exception err) {
            JOptionPane.showMessageDialog(null, "更新列表失败！");
            err.printStackTrace();
        }

        if (userContro.getUser() != null) {
            log.info("更新列表!");
            if (needLogOut) {
                needLogOut = false;
                JOptionPane.showMessageDialog(null, "您可能修改了自己的信息，请重新登录");
                userContro.logOut();
                frame.dispose();
                new Login().start();
                return;
            }
            try {
                UserList tl = userContro.getSavedUserListOrDefault();
                if (tl.getData().size() == 0) {
                    JOptionPane.showMessageDialog(null, "无法添加默认用户");
                }
                tablenr = new Object[tl.getData().size()][6];
                DefaultTableModel tbmd = new DefaultTableModel(new String[]{"用户ID", "姓名", "权限等级", "生日", "电话", "性别"}, 0);
                tbmd.setRowCount(0);
                int j = 0;
                for (int i = 0; i < tl.getData().size(); ++i) {
                    if (userContro.getUser().permission != 3 && !Objects.equals(tl.getData().get(i).getName(), userContro.getUser().getName()))
                        continue;
                    tablenr[j][0] = tl.getData().get(i).getAccount();
                    tablenr[j][1] = tl.getData().get(i).getName();
                    tablenr[j][2] = tl.getData().get(i).permission == 1 ? "后勤管理" : tl.getData().get(i).permission == 2 ? "生活管家" : tl.getData().get(i).permission == 3 ? "管理员" : "配置文件损坏";
                    tablenr[j][3] = tl.getData().get(i).getBirthday();
                    tablenr[j][4] = tl.getData().get(i).getPhone();
                    tablenr[j][5] = tl.getData().get(i).isMale() ? "男" : "女";
                    tbmd.addRow(tablenr[j]);
                    ++j;
                }
                table1.setModel(tbmd);
                table1.getColumn("电话").setPreferredWidth(100);
            } catch (Exception err) {
                JOptionPane.showMessageDialog(null, "更新列表失败！" + err);
            }
        }
    }
}
